<?php

namespace app\admin\command;

use think\Hook;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Collection;
use think\Db;
use think\Exception;
use think\Log;
use fast\Random;
use app\common\library\CheckID;

class Test extends Command
{
    protected function configure()
    {   
        $this->setName('test')
            ->setDescription('test command');
    }   

    protected function execute(Input $input, Output $output)
    {
        echo Random::alnum(8);
        /*
        //获取文件内容
        $img = "/Users/sss020/Downloads/card_login.jpg";
        $file_content = file_get_contents($img);
        if($file_content === false){
            return $img;
        }
        $imageInfo = getimagesize($img);
        $prefiex = '';
        $prefiex = 'data:' . $imageInfo['mime'] . ';base64,';
        $base64 = $prefiex.base64_encode($file_content);
        echo $base64;
         */
        /*
        $name = '张几';
        $IDCard = '421002198001311836';
        $ret = CheckID::CheckNameAndID($name, $IDCard);
        var_dump($ret);
         */
        /*
        // 云市场分配的密钥Id
        $secretId = 'AKIDm9xtdn9q3a3vgxg93wBjuflecgrcjHzaj0m6';
        // 云市场分配的密钥Key
        $secretKey = 'bxg2XYdT6jK8qyj59vh2b7kKAHrwIlLAWH7MaALa';

        $secretId = 'AKIDFT36flIi9lL57jvntq61jCysgQllb2xMEuGi';
        // 云市场分配的密钥Key
        $secretKey = '6cbs4u7y71ajfzw85tecdjndn8fzarhuv1ey68la';

        $source = 'market';

        // 签名
        $datetime = gmdate('D, d M Y H:i:s T');
        $signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
        $sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
        $auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);

        // 请求方法
        $method = 'POST';
        // 请求头
        $headers = array(
            'X-Source' => $source,
            'X-Date' => $datetime,
            'Authorization' => $auth,
            
        );
        var_dump($headers);
        // 查询参数
        $queryParams = array (

        );
        // body参数（POST方法下）
        $bodyParams = array (
            'idcard' => '421002198001311838',
            'name' => '张纪',
            'idcard' => '320902201208130195',
            'name' => '张云浩',
        );
        // url参数拼接
        $url = 'https://service-jo9yed8n-1308811306.sh.apigw.tencentcs.com/release/v2/id_name/verify';
        $url = 'https://service-cj0o6t43-1308811306.sh.apigw.tencentcs.com/release/id_name/verify';
        if (count($queryParams) > 0) {
            $url .= '?' . http_build_query($queryParams);
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($v, $k) {
            return $k . ': ' . $v;
        }, array_values($headers), array_keys($headers)));
        if (in_array($method, array('POST', 'PUT', 'PATCH'), true)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($bodyParams));
        }

        $data = curl_exec($ch);
        if (curl_errno($ch)) {
            echo "Error: " . curl_error($ch);
        } else {
            print_r($data);
        }
        curl_close($ch);
        */
    }
}
